import type { User } from '@/types/user'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const user = ref<User>()
    const returnUrl = ref()

    const setUser = (val: User) => {
      user.value = val
    }

    const clearUser = () => {
      user.value = undefined
    }

    const setReturnUrl = (val?: string) => {
      returnUrl.value = val
    }

    return {
      user,
      setUser,
      clearUser,
      returnUrl,
      setReturnUrl
    }
  },
  {
    persist: {
      paths: ['user']
    }
  }
)
